<template>
  <div class="favorites">
    <div class="container">
      <h2>我的收藏</h2>
      <div class="favorites-list" v-if="favoritesList.length > 0">
        <div v-for="item in favoritesList" :key="item.id" class="favorite-item">
          <img :src="item.image" :alt="item.name">
          <div class="item-info">
            <h3>{{ item.name }}</h3>
            <p class="price">¥{{ item.price }}</p>
            <div class="actions">
              <button @click="addToCart(item)">加入购物车</button>
              <button @click="removeFavorite(item.id)" class="remove">取消收藏</button>
            </div>
          </div>
        </div>
      </div>
      <div v-else class="empty-favorites">
        <p>暂无收藏商品</p>
        <router-link to="/" class="go-shopping">去购物</router-link>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const favoritesList = ref([])

// 添加到购物车
const addToCart = (item) => {
  // TODO: 实现添加到购物车的逻辑
  console.log('添加到购物车', item)
}

// 取消收藏
const removeFavorite = (id) => {
  // TODO: 实现取消收藏的逻辑
  favoritesList.value = favoritesList.value.filter(item => item.id !== id)
}
</script>

<style scoped>
.favorites {
  padding: 20px 0;
  background-color: var(--bg-color-page);
  min-height: calc(100vh - 200px);
}

.container {
  width: 1200px;
  margin: 0 auto;
}

h2 {
  margin-bottom: 20px;
}

.favorites-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.favorite-item {
  background: var(--bg-color);
  border-radius: 8px;
  padding: 15px;
  transition: all 0.3s;
}

.favorite-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.favorite-item img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 4px;
}

.item-info {
  margin-top: 10px;
}

.item-info h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
}

.price {
  color: var(--primary-color);
  font-size: 18px;
  font-weight: bold;
  margin: 10px 0;
}

.actions {
  display: flex;
  gap: 10px;
}

.actions button {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.actions button:first-child {
  background-color: var(--primary-color);
  color: white;
}

.actions button.remove {
  background-color: #f5f5f5;
  color: #666;
}

.empty-favorites {
  text-align: center;
  padding: 40px 0;
}

.go-shopping {
  display: inline-block;
  margin-top: 20px;
  padding: 10px 20px;
  background-color: var(--primary-color);
  color: white;
  text-decoration: none;
  border-radius: 4px;
}
</style>